import { Pool as PgPool } from 'pg';
import { Pool as MySQLPool } from 'mysql2/promise';
import { DatabaseType } from './database.js';

export interface AppContext {
  // Koa Context 基本属性
  body?: unknown;
  status?: number;
  headers: {
    [key: string]: string | string[] | undefined;
    authorization?: string;
  };
  cookies: {
    get(name: string): string | undefined;
    set(
      name: string,
      value: string | null,
      options?: {
        maxAge?: number;
        expires?: Date;
        path?: string;
        domain?: string;
        secure?: boolean;
        httpOnly?: boolean;
        sameSite?: 'strict' | 'lax' | 'none';
        signed?: boolean;
      }
    ): void;
  };
  path: string;
  originalUrl: string;
  params: Record<string, string>;
  query: Record<string, string | string[] | undefined>;
  request: Record<string, unknown>;
  response: Record<string, unknown>;
  state: Record<string, unknown>;
  method: string;
  set: (field: string, val: string) => void;
  ip: string;

  // 自定义属性
  mysqlPool?: MySQLPool;
  postgresPool?: PgPool;
  getDbPool: () => MySQLPool | PgPool;
  dbType: DatabaseType;
}

export interface HealthCheckResponse {
  status: string;
  timestamp: string;
}
